// pages/commentSubmit/commentSubmit.js
const util = require("../../utils/util.js");

Page({

  /**
   * 页面的初始数据
   */
  data: {
    inputTxt:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

    //console.log(this.getDateStr());
  },
  onInput(e){
    const value = e.detail.value;
    this.setData({inputTxt:value});//
  },
  onSubmit(e){
    const app = getApp();
    const value = this.data.inputTxt;
    const datestr = this.getDateStr();
    wx.cloud.callFunction({
      name: 'quickstartFunctions',
      data:{
        type:"setComment",
        openid:app.globalData.openid,
        desc:value,
        datestr:datestr
      },
      complete: res => {
        console.log('setComment: ', res);//
        util.gotoCommentMePage();
      }
    })
  },
  getDateStr(){
    var date = new Date();
    var year = date.getFullYear();
    if(year < 10){ year = "0"+year; }
    var month = date.getMonth() + 1;
    if(month < 10){ month = "0"+month; }
    var day = date.getDate();
    if(day < 10){ day = "0"+day; }
    const str1 = year + "-" + month + "-" + day;
    
    var year = date.getHours()
    if(year < 10){ year = "0"+year; }
    var month = date.getMinutes();
    if(month < 10){ month = "0"+month; }
    var day = date.getSeconds();
    if(day < 10){ day = "0"+day; }
    const str2 = year + ":" + month + ":" + day;

    return str1 + " " + str2;
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})